public class so {
	public int computeScore() {
		boolean vulnerable = false;
		int score = 0;
		int bidValue = highBid.getValue();// contractnumber
		int numTricks = getNumberOfTricks(highBid.getPlayer() % 2);// contractnumber
																	// + tricks1

		// Determines if a contract is doubled or redoubled
		int code = 1;// redouble
		if (highBid.isReDoubled()) {
			code = 4;
		} else if (highBid.isDoubled()) {
			code = 2;
		}

		// Determines vulnerability
		switch (declarer) {// by NSEW
		case GameInterface.NORTH:
		case GameInterface.SOUTH:
			vulnerable = (getVulnerability() == GameInterface.VULNERABLE_ALL)
					| (getVulnerability() == GameInterface.VULNERABLE_NS);
			break;
		case GameInterface.EAST:
		case GameInterface.WEST:
			vulnerable = (getVulnerability() == GameInterface.VULNERABLE_ALL)
					| (getVulnerability() == GameInterface.VULNERABLE_EW);
			break;
		}

		// Calculates the score
		if (bidValue == 0) {
			score = 0;
		} else {
			int drawValue = 0, overTricks, extra = 0, bonus = 0;
			overTricks = numTricks - (bidValue + 6);// tricks2

			if (numTricks < bidValue + 6) { // The declaring pair didn't fulfill
											// the contract

				int underTricks = bidValue + 6 - numTricks;

				if (vulnerable) {
					if (highBid.isReDoubled()) {
						score = 400 + (underTricks - 1) * 600;
					} else if (highBid.isDoubled()) {
						score = 200 + (underTricks - 1) * 300;
					} else {
						score = underTricks * 100;
					}
				} else {
					if (highBid.isReDoubled()) {
						if (underTricks <= 3) {
							score = 100 + (underTricks - 1) * 200;
						} else {
							score = 500 + (underTricks - 3) * 300;
						}
						score *= 2;
					} else if (highBid.isDoubled()) {
						if (underTricks <= 3) {
							score = 100 + (underTricks - 1) * 200;
						} else {
							score = 500 + (underTricks - 3) * 300;
						}
					} else {
						score = underTricks * 50;
					}
				}

				score = -score;
			} else { // The declaring pair made the contract.

				if (highBid.getSuit() == null) {
					drawValue = (40 + (bidValue - 1) * 30) * code;
					extra = overTricks * 30;
				} else if (highBid.getSuit().equals("d")
						|| highBid.getSuit().equals("c")) {
					drawValue = bidValue * 20 * code;
					extra = overTricks * 20;
				} else if (highBid.getSuit().equals("h")
						|| highBid.getSuit().equals("s")) {
					drawValue = bidValue * 30 * code;
					extra = overTricks * 30;
				}

				switch (code) {
				case 2:
					if (vulnerable) {
						extra = 50 + overTricks * 200;
					} else {
						extra = 50 + overTricks * 100;
					}
					break;
				case 4:
					if (vulnerable) {
						extra = 100 + overTricks * 400;
					} else {
						extra = 100 + overTricks * 200;
					}
					break;
				}

				if (drawValue >= 100) {
					if (vulnerable) {
						bonus = 500;
						if (bidValue == 6) {
							bonus += 750;
						}
						if (bidValue == 7) {
							bonus += 1500;
						}
					} else {
						bonus = 300;
						if (bidValue == 6) {
							bonus += 500;
						}
						if (bidValue == 7) {
							bonus += 1000;
						}
					}
				} else {
					bonus = 50;
				}

				score = drawValue + extra + bonus;
			}
		}
		return score;
	}
}
